package com.jinlejia.erp.ui.common;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import androidx.appcompat.app.AlertDialog;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.TextView;

import com.jinlejia.erp.R;

/**
 * 客户评价（Dialog）
 */

public class EvaluateDialog extends AlertDialog implements View.OnClickListener {
    private String evaStr;
    private int level = 0;

    public EvaluateDialog(Context context, int level, String eva) {
        super(context);
        this.level = level;
        this.evaStr = eva;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = this.getWindow();
        this.setCanceledOnTouchOutside(true);
        // *** 主要就是在这里实现这种效果的.
        // 设置窗口的内容页面,shrew_exit_dialog.xml文件中定义view内容
        window.setContentView(R.layout.dialog_evaluate);
        window.setGravity(Gravity.CENTER);
        window.setBackgroundDrawable(new ColorDrawable());
        window.setLayout(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        window.findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        ((RatingBar) window.findViewById(R.id.ratingbar)).setRating(level);
        ((TextView) window.findViewById(R.id.ev_text)).setText(evaStr);

    }

    @Override
    public void onClick(View v) {

    }

    public interface OnConfirmListener {
        public void confirm();
    }

    private OnConfirmListener confirmListener;

    public void setConfirmListener(OnConfirmListener listener) {
        this.confirmListener = listener;
    }
}
